package com.yhy.shiro.test2.permission;

import java.util.Arrays;
import java.util.Collection;

import org.apache.shiro.authz.Permission;
import org.apache.shiro.authz.permission.RolePermissionResolver;
import org.apache.shiro.authz.permission.WildcardPermission;


/**
 * RolePermissionResolver用于根据角色字符串来解析得到权限集合。
 * @author yhy
 *
 */
public class MyRolePermissionResolver implements RolePermissionResolver {

	/**
	 * 此处的实现很简单，如果用户拥有role1，那么就返回一个“menu:*”的权限。
	 */
	@Override
	public Collection<Permission> resolvePermissionsInRole(String roleString) {
		System.out.print("MyRolePermissionResolver" + "根据角色赋予权限。角色: " + roleString );
		if("role1".equals(roleString)) { 
			System.out.println(" 获得 meun:* 权限");
            return Arrays.asList((Permission)new WildcardPermission("menu:*"));  
        }
		System.out.println(" 没有获得权限");
		return null;
	}

}
